// pages/tags/tags.js
import config from '../../utils/config.js'
var Api = require('../../utils/api.js');
var util = require('../../utils/util.js');
var Auth = require('../../utils/auth.js');
var wxApi = require('../../utils/wxApi.js')
var wxRequest = require('../../utils/wxRequest.js');
const Adapter = require('../../utils/adapter.js')
var webSiteName = config.getWebsiteName;
var domain = config.getDomain
var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    tagList: [],
    loading: false,
    page: 1,
    pageSize: 100,
    webSiteName: webSiteName,
    domain: domain,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.getTags();
  },
  getTags() {
    var self = this;
    self.setData({
      tagList: [],
      loading: true
    });
    var getTagsRequest = wxRequest.getRequest(Api.getTags(this.data.page, this.data.pageSize));
    getTagsRequest.then(res => {
      console.log(res.data);
      this.setData({
        tagList: res.data
      })
    }).finally(res => {
      this.setData({
        loading: false
      });
    });
  },
  //跳转至某分类下的文章列表
  redictIndex: function (e) {
    //console.log('查看某类别下的文章');  
    var id = e.currentTarget.dataset.id;
    var url = '../list/list?tagID=' + id;
    wx.navigateTo({
      url: url
    });
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})